/**
 * 考試管理初始化
 */
var CompletedTesting = {
    id: "CompletedTestingTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    CompletedTestingData: {},
    layerIndex: -1
};
var ProType = {
        type: null
    }
;
/**
 * 初始化表格的列
 */
CompletedTesting.initColumn = function () {
    return [
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle', hidden: true},
        {
            title: 'testQuestionsId',
            field: 'testQuestionsId',
            visible: false,
            align: 'center',
            valign: 'middle',
            hidden: true
        },
        {title: 'userAnswer', field: 'userAnswer', visible: false, align: 'center', valign: 'middle', hidden: true},
        {title: 'testNumber', field: 'testNumber', visible: false, align: 'center', valign: 'middle', hidden: true},
        {
            title: '', field: 'testTitle', align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                if (row.userAnswer == undefined) {
                    row.userAnswer = "";
                }
                if(row.userAnswer==row.correctAnswer){
                    return row.testNumber + "." + value + "   (" + " " + row.userAnswer + " " + ")"+"  正确";
                }
                if(row.userAnswer!=row.correctAnswer){
                    return row.testNumber + "." + value + "   (" + " " + row.userAnswer + " " + ")"+"  错误";
                }
            }
        },
        {title: 'A：', field: 'optionsA', align: 'center', valign: 'middle',},
        {title: 'B：', field: 'optionsB', align: 'center', valign: 'middle',},
        {title: 'C：', field: 'optionsC', align: 'center', valign: 'middle',},
        {title: 'D：', field: 'optionsD', align: 'center', valign: 'middle',},
        {title: 'E：', field: 'optionsE', align: 'center', valign: 'middle',},
        {title: 'F：', field: 'optionsF', align: 'center', valign: 'middle',},
        {
            title: '',
            field: 'correctAnswer',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                if (value == undefined) {
                    value = "";
                }
                return "正确答案：" + value;
            }
        },
    ];
};


/**
 * 检查是否选中
 */
CompletedTesting.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CompletedTesting.seItem = selected[0];
        return true;
    }
};

CompletedTesting.getMoney = function (url) {
    window.location.href = url;
}
/**
 * 清除数据
 */
CompletedTesting.clearData = function () {
    this.CompletedTestingData = {};
}
CompletedTesting.collectData = function () {
    this.set('theTestId').set('userId');
}
CompletedTesting.set = function (key, val) {
    this.CompletedTestingData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}


CompletedTesting.resetSearch = function () {
    $("#theTestId").val("");
    $("#userId").val("");
    CompletedTesting.search();
};

CompletedTesting.formParams = function () {
    var queryData = {};
    queryData['theTestId'] = $("#theTestId").val();
    queryData['userId'] = $("#userId").val();
    return queryData;
}

var parseParam = function (param, key) {
    var paramStr = "";
    if (param instanceof String || param instanceof Number || param instanceof Boolean) {
        paramStr += "&" + key + "=" + param;
    } else {
        $.each(param, function (i) {
            var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
            paramStr += '&' + parseParam(this, k);
        });
    }
    return paramStr.substr(1);
};

/**
 * 查询考試列表
 */
CompletedTesting.search = function () {
    CompletedTesting.table.refresh({query: CompletedTesting.formParams()});
};

$(function () {
    document.getElementById("theTestId").style.display = "none";
    document.getElementById("theTestName").style.display = "none";
    document.getElementById("userName").style.display = "none";
    document.getElementById("userId").style.display = "none";
    var defaultColunms = CompletedTesting.initColumn();
    var table = new BSTable(CompletedTesting.id, "/getTestGenerate/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(CompletedTesting.formParams());
    CompletedTesting.table = table.init();
    brs.innerHTML="</br></br></br></br>";
    br5s.innerHTML="</br></br></br></br></br>"
});
